package orbitPrototype.render;

import java.awt.Canvas;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;

import orbitPrototype.Settings;
import orbitPrototype.game.Game;
import orbitPrototype.input.MouseInput;

public class Frame extends JFrame
{	
	public Frame(Game game)
	{		
		this.setIgnoreRepaint(true);
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("ORBITER");
		
		
		Canvas canvas = new Canvas();
		canvas.setIgnoreRepaint(true);
		canvas.setFocusable(false);
		canvas.setSize(Settings.FRAME_WIDTH,Settings.FRAME_HEIGHT);
		
		this.add(canvas);
		this.pack();
		this.setVisible(true);
		
		// Mouse listener
		MouseInput mouse = game.getMouseInput();
		canvas.addMouseListener(mouse);
		canvas.addMouseMotionListener(mouse);
		
		canvas.createBufferStrategy(2);
		BufferStrategy bufferStrategy = canvas.getBufferStrategy();
		
		// Get screen device, configuration
		GraphicsEnvironment graphicsEnviorment = GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsDevice graphicsDevice = graphicsEnviorment.getDefaultScreenDevice();
		GraphicsConfiguration graphicsConfiguration = graphicsDevice.getDefaultConfiguration();
		
		BufferedImage bufferedImage = graphicsConfiguration.createCompatibleImage(Settings.FRAME_WIDTH, Settings.FRAME_HEIGHT);
	
		Render render = new Render(game, bufferedImage, bufferStrategy);
		Thread renderThread = new Thread(render);
		renderThread.start();
	}
}
